import pandas as pd
import numpy as np


def mark_vol_raise_score(df):
    df['d_turnover_max'] = df.groupby('code')['turnover'].transform(lambda x: x.rolling(window=60, min_periods=1).max())
    df.loc[:,'max_pct'] = df.code.apply(lambda x: 10 if (x.startswith('0') or x.startswith('60')) else 20)
    df['raise_score'] = df['r1']/df['max_pct']
    df['turnover_score'] = df['turnover']/df['d_turnover_max']
    df['score'] = df['raise_score']* df['turnover_score']
    df.loc[:,'d10_max'] =  df.code.apply(lambda x: 100 if (x.startswith('0') or x.startswith('60')) else 150)
    df['r_d10_score'] = 1 - df['r10']/df['d10_max']
    df['final_score'] = df['score']* df['r_d10_score']
    return df